package com.hudongwx.sadpw.activity;

import android.support.v4.app.FragmentTabHost;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;

import com.hudongwx.sadpw.R;
import com.hudongwx.sadpw.fragment.CommunityFragment;
import com.hudongwx.sadpw.fragment.HomePageFragment;
import com.hudongwx.sadpw.fragment.MyFragment;
import com.hudongwx.sadpw.fragment.ShoppingCarFragment;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import static com.hudongwx.sadpw.R.id.btn_tv;

@ContentView(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {
    @ViewInject(android.R.id.tabhost)
    private FragmentTabHost tabHost;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        initFragment();
    }

    private void initFragment() {
        tabHost.setup(this,getSupportFragmentManager(),android.R.id.tabcontent);
        tabHost.addTab(tabHost.newTabSpec("home").setIndicator(getTabs("首页",R.drawable.home_page)), HomePageFragment.class,null);
        tabHost.addTab(tabHost.newTabSpec("comm").setIndicator(getTabs("社区",R.drawable.community_select)), CommunityFragment.class,null);
        tabHost.addTab(tabHost.newTabSpec("shop").setIndicator(getTabs("购物",R.drawable.shopping_select)), ShoppingCarFragment.class,null);
        tabHost.addTab(tabHost.newTabSpec("my").setIndicator(getTabs("我的",R.drawable.my_select)), MyFragment.class,null);
    }
    private View getTabs(String name,int img){
        View view = getLayoutInflater().inflate(R.layout.btn_item, null);
        ImageView imageView= (ImageView) view.findViewById(R.id.btn_iv);
        TextView textView= (TextView) view.findViewById(R.id.btn_tv);
        imageView.setImageResource(img);
        textView.setText(name);
        return view;
    }
}
